package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Movement;
import com.tanhua.server.service.MovementMqService;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/movements")
public class MovementsController {

    @Autowired
    private MovementService movementService;
    @Autowired
    private MovementMqService movementMqService;

    @PostMapping(name = "发布动态（圈子）") //这里千万不要加@RequestBody
    public ResponseEntity saveMovements(Movement movement, MultipartFile[] imageContent) throws Exception{
        return movementService.saveMovement(movement,imageContent);
    }

    @GetMapping(name = "查询好友发布的动态")
    public ResponseEntity queryFriendMovements(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{
        return movementService.queryFriendMovements(page,pagesize);
    }

    @GetMapping(value = "/recommend",name = "查询推荐的动态")
    public ResponseEntity queryRecommendMovements(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{
        return movementService.queryRecommendMovements(page,pagesize);
    }

    @GetMapping(value = "/all",name = "查询指定用户（我）的动态")
    public ResponseEntity queryMyselfMovements(@RequestParam(defaultValue = "1") Integer page,
                                                  @RequestParam(defaultValue = "10")Integer pagesize,Long userId) throws Exception{
        return movementService.queryMyselfMovements(page,pagesize,userId);
    }

    @GetMapping(value = "/{id}/like",name = "动态（圈子）点赞")
    public ResponseEntity like(@PathVariable("id") String movementId) throws Exception{
        movementMqService.sendMsgToMq(movementId,2);
        return movementService.like(movementId);
    }


    @GetMapping(value = "/{id}/dislike",name = "动态（圈子）取消点赞")
    public ResponseEntity dislike(@PathVariable("id") String movementId) throws Exception{
        movementMqService.sendMsgToMq(movementId,5);
        return movementService.dislike(movementId);
    }


    @GetMapping(value = "/{id}/love",name = "动态（圈子）喜欢")
    public ResponseEntity love(@PathVariable("id") String movementId) throws Exception{
        movementMqService.sendMsgToMq(movementId,3);
        return movementService.love(movementId);
    }


    @GetMapping(value = "/{id}/unlove",name = "动态（圈子）取消喜欢")
    public ResponseEntity unlove(@PathVariable("id") String movementId) throws Exception{
        movementMqService.sendMsgToMq(movementId,6);
        return movementService.unlove(movementId);
    }
//    movements
    @GetMapping(value = "/{id}",name = "查询单条动态（圈子）")
    public ResponseEntity queryMovementById(@PathVariable("id") String movementId) throws Exception{
//        movementId = "visotors";
        movementMqService.sendMsgToMq(movementId,1);
        return movementService.queryMovementById(movementId);
    }

    @GetMapping(value = "/visitors",name = "谁看过我")
    public ResponseEntity queryVisitors() throws Exception{

        return movementService.queryVisitors(4);
    }



}
